package com.isoftstone.util;

import oracle.sql.CLOB;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 类名称：类型转换工具类
 * @author：guoX
 * @date: 2016/6/19
 */
public class OracleClobTypeHandler implements TypeHandler<Object>{

    public void setParameter(PreparedStatement preparedStatement, int i, Object o, JdbcType jdbcType) throws SQLException {
        CLOB clob = CLOB.empty_lob();
        clob.setString(1, (String) o);
        preparedStatement.setClob(i, clob);
    }

    public Object getResult(ResultSet resultSet, String s) throws SQLException {
        CLOB clob = (CLOB) resultSet.getClob(s);
        return (clob == null || clob.length() == 0) ? null : clob.getSubString((long) 1, (int) clob.length());
    }

    public Object getResult(ResultSet resultSet, int i) throws SQLException {
        return null;
    }

    public Object getResult(CallableStatement callableStatement, int i) throws SQLException {
        return null;
    }
}
